define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {  
                   loading:0,
                    page:1,
                    status:0,
                    lastpage:0,
                    listData:[],
                    nodata:0
                };
            },
            el: '#pageOrder',
            created: function() {
                this.fetchData();
            },
            mounted: function() {
                    // console.log("123");
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageOrder",function(){
                       that.loadOderList();
                    });
                    this.mounted = 1;

            },
            methods: {
                fetchData: function() {
                    if (this.$route.params.status){
                      this.status = this.$route.params.status;
                    }
                    this.loadOderList();
                },
                setStatus:function(status){
                    // var status = $(e.target).attr("data-status");

                    if (this.status === status){
                      return ;
                    }
                      console.log(status);
                    this.status  = status;
                     
                    this.loadOderList(1);
                   
                },  
                topay:function(order_sn){
                  app.pay(order_sn);
                },

              loadOderList:function(reload){
                var that = this;
               
                if (reload == 1) {
                    this.loading= 0;
                    this.page=1;
                    this.lastpage= 0;
                    this.listData= [];
                }

                var page = this.page;
                if (this.loading == 1 || this.lastpage == 1) {
                  return;
                }
                var params = {
                  page: page,
                  limit: 10,
                  status: this.status,
                  order: 'addtime desc'
                };

                if(this.$route.params.store_id ){
                  params.store_id = this.$route.params.store_id;
                }

                this.loading = 1;
                app.get("apiv2/order/get",params , function (res) {
                  that.loading = 0;
                  if (res.code != 200) {
                    app.alert(res.msg);
                    return;
                  }
                  // console.log(res);
                  if (res.data.list.length === 0) {
                    that.lastpage = 1;
                  }
                  that.page++;
                  var listData = that.listData;
                  that.listData=listData.concat(res.data.list);
                  if(that.listData.length === 0){
                    that.nodata=1;
                  }else{
                    that.nodata=0;
                  }
                  
                });

              },
 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
